<template>
	<view class="mine">
		<view class="headerBg"></view>
		<uv-navbar title="个人中心" leftIconSize="0" titleStyle="color:#fff" bgColor="transparent" placeholder>
		</uv-navbar>
		<view class="userInfo">
			<image class="avatar" :src="userInfo.avatar?userInfo.avatar:'../../static/images/logo.jpg'" mode=""></image>
			<view class="userInfo-md">
				<view class="userInfo-md-tp">
					<view class="name">{{userInfo.name}}</view>
					<view class="dept" v-if="userInfo.organize_name">{{userInfo.organize_name}}</view>
				</view>
				<view class="userInfo-md-tb">
					{{userInfo.phone?userInfo.phone:''}}
				</view>
			</view>
			<!-- <image class="toRight" src="../../static/images/toRight.png" mode=""></image> -->
		</view>
		<view class="mineInfo">
			<block v-for="(item, index) in settingList" :key="index">
				<view class="mineInfo-item" v-if="!item.hidden" @click="toPage(item)">
					<image class="img1" :src="item.url" mode=""></image>
					<view class="label">{{item.name}}</view>
					<image class="img2" src="../../static/images/arrow.png" mode=""></image>
				</view>
			</block>
		</view>
		<uv-modal ref="modal" title="是否退出登录?" :showCancelButton="true" @confirm="confirm"></uv-modal>
		<Tabbar :selectedIndex="1"></Tabbar>
	</view>
</template>

<script>
	import reqApi from "../../api/api.js";
	export default {
		data() {
			return {
				settingList: [{
						url: "../../static/images/s1.png",
						name: "个人信息",
						path: `/pages/mine/userInfo?prevpage=mine`,
					},
					{
						url: "../../static/images/s2.png",
						name: "成员管理",
						path: "/pages/home/sellerList",
						hidden: true
					},
          {
          	url: "../../static/images/s4.png",
          	name: "派单详细规则",
            path: "/pages/mine/rules"
          },
					{
						url: "../../static/images/s3.png",
						name: "退出登录"
					},
				],
				userInfo: {
					phone: ""
				}
			}
		},
		onShow() {
			this.getUserInfo();
		},
		methods: {
			toPage(item) {
				if (item.name == "退出登录") {
					this.$refs.modal.open();
					return
				}
				uni.navigateTo({
					url: item.path
				})
			},
			confirm() {
				uni.showToast({
					title: "退出成功",
					icon: 'none',
					mask: true,
					duration: 1500,
				})
				setTimeout(() => {
					uni.removeStorageSync("token");
					uni.removeStorageSync("userInfo");
					uni.reLaunch({
						url: "/pages/login/index"
					})
					this.$refs.modal.close();
				}, 1500)

			},
			getUserInfo() {
				reqApi.getUserInfo({}).then(res => {
					console.log("获取用户信息", res);
					this.userInfo = res.data;
					// 商务管理
					if (res.data.is_manage == 1) {
						this.settingList[1].hidden = false;
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.userInfo {
		display: flex;
		justify-content: space-between;
		align-items: center;
		position: relative;
		z-index: 100;
		margin-top: 40rpx;

		.avatar {
			width: 136rpx;
			height: 136rpx;
			margin-right: 30rpx;
			border-radius: 50%;
		}

		.userInfo-md {
			flex: 1;
			display: flex;
			justify-content: space-between;
			flex-direction: column;

			.userInfo-md-tp {
				display: flex;

				.name {
					font-family: Microsoft YaHei UI, Microsoft YaHei UI;
					font-weight: bold;
					font-size: 36rpx;
					color: #FFFFFF;
					margin-right: 10rpx;
				}

				.dept {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 22rpx;
					color: #FFFFFF;
					border-radius: 10rpx 10rpx 10rpx 10rpx;
					border: 2rpx solid rgba(255, 255, 255, 0.3);
					padding: 0 12rpx;
					box-sizing: border-box;
					display: flex;
					align-items: center;
				}
			}

			.userInfo-md-tb {
				font-family: Microsoft YaHei UI, Microsoft YaHei UI;
				font-weight: 400;
				font-size: 28rpx;
				color: #FFFFFF;
				margin-top: 14rpx;
			}
		}

		.toRight {
			width: 24rpx;
			height: 48rpx;
		}
	}

	.headerBg {
		width: 750rpx;
		height: 704rpx;
		background: linear-gradient(to top, rgba(16, 113, 231, 0) 0%, #1071E7 100%);
		position: absolute;
		top: 0;
		left: 0;
	}

	.mine {
		position: relative;
		padding: 0 30rpx;
		box-sizing: border-box;

		.mineInfo {
			background: #fff;
			border-radius: 40rpx;
			margin-top: 62rpx;
			position: relative;
			z-index: 50;

			.mineInfo-item {
				height: 112rpx;
				padding: 0 40rpx;
				box-sizing: border-box;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 2rpx solid #eee;

				.img1 {
					width: 40rpx;
					height: 40rpx;
				}

				.label {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #333333;
					flex: 1;
					margin: 0 20rpx;
				}

				.img2 {
					width: 40rpx;
					height: 40rpx;
				}
			}
		}
	}
</style>
